"use strict";
cc._RF.push(module, '7ab0ddVHThF5qj8BsF0MV6B', 'PageBase');
// scripts/Game/Base/PageBase.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../engines/gameEngine");
var gameMode_json_1 = require("../../engines/managers/gameContent/gameMode_json");
var Enum_1 = require("../Enum");
var MainRoot_1 = require("../MainRoot");
var PageBase = /** @class */ (function (_super) {
    __extends(PageBase, _super);
    function PageBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.m_mode = gameMode_json_1.GAME_MODE.NORMAL;
        _this.registed = false;
        _this.content = null;
        _this.btnRoot = null;
        _this.onClose = null;
        _this.onReward = null;
        return _this;
    }
    PageBase.prototype.OnPageOpen = function (prams) {
        return __awaiter(this, void 0, void 0, function () {
            var labelName, labelName, labelName, _loop_1, this_1, index;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        prams && (this.m_mode = prams.mode);
                        prams && (this.onReward = prams.onReward);
                        prams && (this.onClose = prams.onClose);
                        this.node.opacity = 0;
                        if (!this.registed) {
                            this.AddEvent();
                        }
                        this.content = this.node.getChildByName("Content");
                        this.btnRoot = this.node.getChildByName("ButtonRoot");
                        this.btnRoot && this.btnRoot.children.forEach(function (node) {
                            node.opacity = 0;
                        });
                        if (this.content) {
                            this.content.scale = 0;
                        }
                        if (prams && prams.index == 112 && prams.loseText != undefined) {
                            labelName = "Label" + prams.index;
                            this.content.getChildByName(labelName).getComponentInChildren(cc.Label).string = prams.loseText;
                        }
                        if (prams && prams.index == 113 && prams.loseText != undefined) {
                            labelName = "Label" + prams.index;
                            this.content.getChildByName(labelName).getComponentInChildren(cc.Label).string = prams.loseText;
                        }
                        if (prams && prams.index == 147 && prams.loseText != undefined) {
                            labelName = "Label" + prams.index;
                            this.content.getChildByName(labelName).getComponentInChildren(cc.Label).string = prams.loseText;
                        }
                        cc.tween(this.node).to(0.25, { opacity: 255 }).start();
                        if (!this.content) return [3 /*break*/, 2];
                        return [4 /*yield*/, new Promise(function (resolve) {
                                cc.tween(_this.content).delay(0.2).call(function () {
                                    // O1HD.getManagers().soundMgr.playSound("tanchuang");
                                }).to(0.3, { scale: 1 }, { easing: 'backOut' }).call(resolve).start();
                            })];
                    case 1:
                        _a.sent();
                        _a.label = 2;
                    case 2:
                        if (!this.btnRoot) return [3 /*break*/, 6];
                        _loop_1 = function (index) {
                            var element;
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0:
                                        element = this_1.btnRoot.children[index];
                                        return [4 /*yield*/, new Promise(function (resolve, reject) {
                                                cc.tween(element).to(0.2, { opacity: 255 }).call(resolve).start();
                                            })];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        };
                        this_1 = this;
                        index = 0;
                        _a.label = 3;
                    case 3:
                        if (!(index < this.btnRoot.children.length)) return [3 /*break*/, 6];
                        return [5 /*yield**/, _loop_1(index)];
                    case 4:
                        _a.sent();
                        _a.label = 5;
                    case 5:
                        index++;
                        return [3 /*break*/, 3];
                    case 6: return [2 /*return*/];
                }
            });
        });
    };
    PageBase.prototype.ShowPage = function () {
        this.node.active = true;
    };
    PageBase.prototype.HidePage = function () {
        this.node.active = false;
        // this.OnPageClose();
        // mainRoot.UISystem.HidePage(this.pageName);
    };
    PageBase.prototype.ClosePage = function () {
        MainRoot_1.default.UISystem.ClosePage(this.pageName);
    };
    PageBase.prototype.OnPageClose = function () {
        var _this = this;
        this.RemoveEvent();
        // this.Log("关闭页面");
        this.onClose && this.onClose();
        this.onClose = null;
        this.onReward = null;
        if (this.node.isValid) {
            cc.tween(this.node).to(0.1, { opacity: 0 }).call(function () {
                _this.node.destroy();
            }).start();
        }
    };
    PageBase.prototype.BackMain = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, gameEngine_1.default.getManagers().gameMgr.returnMainScene()];
                    case 1:
                        _a.sent();
                        MainRoot_1.default.UISystem.CloseAllPage();
                        return [2 /*return*/];
                }
            });
        });
    };
    PageBase.prototype.OnMainBtn = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        gameEngine_1.managers().soundMgr.playSound('mainSound/anNiu');
                        return [4 /*yield*/, this.BackMain()];
                    case 1:
                        _a.sent();
                        // if(this.m_mode == GAME_MODE.BHMB||this.m_mode == GAME_MODE.CJTT){
                        //     mainRoot.UISystem.OpenPage(PAGE.LEVELSKINMENU,{
                        //         mode:this.m_mode
                        //     });
                        // }
                        // else{
                        MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.LEVELMENU, {
                            mode: this.m_mode
                        });
                        return [2 /*return*/];
                }
            });
        });
    };
    PageBase.prototype.OnCloseBtn = function () {
        gameEngine_1.managers().soundMgr.playSound('mainSound/anNiu');
        this.ClosePage();
    };
    PageBase.prototype.AddEvent = function () {
        this.registed = true;
        // this.Log("注册事件");
    };
    PageBase.prototype.RemoveEvent = function () {
        // this.Log("注销事件");
        this.registed = false;
    };
    PageBase.prototype.Log = function () {
        var prams = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            prams[_i] = arguments[_i];
        }
        console.log.apply(console, __spreadArrays([this.pageName + ":--->>[\n"], prams, ["\n]"]));
    };
    PageBase.prototype.Warn = function () {
        var prams = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            prams[_i] = arguments[_i];
        }
        console.warn.apply(console, __spreadArrays([this.pageName + ":---[\n"], prams, ["\n]"]));
    };
    PageBase.prototype.onDestroy = function () {
    };
    /** 防止连续点击 */
    PageBase.isPlaySound = false;
    return PageBase;
}(cc.Component));
exports.default = PageBase;

cc._RF.pop();